<?php
/**
 * Created by PhpStorm.
 * User: xaq
 * Date: 2017/5/19
 * Time: 21:37
 */

namespace app\api\model;

use app\api\model\BaseModel;


class Theme extends BaseModel
{
    protected $hidden = ['topic_img_id','head_img_id','update_time','delete_time'];
    public function topicImg() {
        return $this->belongsTo('Image','topic_img_id','id');
    }
    public function headImg() {
        return $this->belongsTo('Image','head_img_id','id');
    }
    //belongsToMany('关联模型名','中间表名','外键名','当前模型关联键名',['模型别名定义']);
    public function products() {
        return $this->belongsToMany('Product','theme_product','product_id','theme_id');
    }

    public static function getThemeWithProducts($id) {
        $theme =  self::with('products,topicImg,headImg')
            ->find($id);
        return $theme;
    }
}